package com.shanzmoo.db.sys.entity.vo;

import com.alibaba.fastjson.JSON;
import com.shanzmoo.db.sys.entity.MenuEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 菜单保存对象
 * @author: Gzhao 2020/11/10
 */
@Data
@Accessors(chain = true)
@ApiModel("人员菜单列表")
public class MenuAuthVo {

    @ApiModelProperty("菜单ID")
    private Integer menuId;

    @ApiModelProperty("菜单类型：0-头部目录，1-左侧一级菜单，2-左侧二级菜单，3-按钮")
    private Integer menuType;

    @ApiModelProperty("菜单图标")
    private String icon;

    @ApiModelProperty("菜单名称")
    private String name;

    @ApiModelProperty("是否隐藏菜单")
    private Boolean hidden;

    @ApiModelProperty("前端路由地址")
    private String path;

    @ApiModelProperty("前端组件路径")
    private String component;

    @ApiModelProperty("权限标识")
    private String perms;

    @ApiModelProperty("排序号")
    private Integer menuIndex;

    @ApiModelProperty("子菜单")
    private List<MenuAuthVo> children;

    public static MenuAuthVo create(MenuEntity menuEntity) {
        MenuAuthVo menuAuthVo = JSON.parseObject(JSON.toJSONString(menuEntity), MenuAuthVo.class);
        return menuAuthVo.setName(menuEntity.getMenuName())
                .setIcon(menuEntity.getMenuIco())
                .setComponent(menuEntity.getComponentPath())
                .setPath(menuEntity.getRouterUrl())
                ;
    }

}
